<template>
	<view class="content">
		<text class="content__title">欢迎注册轻奢行！</text>
		<input class="content__input" type="text" v-model="account" placeholder="请输入您的用户名" />
		<view class="content__pwd">
			<input class="content__input" v-show="!isViewPwd" type="password" v-model="password" placeholder="请设置8位数密码" />
			<input class="content__input" v-show="isViewPwd" type="text" v-model="password" placeholder="请设置8位数密码" />
			<image src="../../../static/images/login/view_pwd.png" @click="viewPwd"></image>
		</view>
		<input class="content__input" type="password" v-model="confirmPassword" placeholder="再次确认密码" />
		<input class="content__input" type="number" v-model="phone" placeholder="请输入手机号" />
		<text class="content__tips">*手机号用于忘记密码时找回密码</text>
		<!-- <input class="content__input" type="text" v-model="inviteCode" placeholder="请输入邀请码（选填）" /> -->
		<button class="content__btn" @click="doRegister">注册</button>
		<text class="content__tologin" @click="toLogin">已有账号，去登录</text>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				account: '',
				password: '',
				confirmPassword: '',
				phone: '',
				inviteCode: '',
				isViewPwd: false,
			}
		},
		methods: {
			doRegister() {
				
				if (!this.password) {
					uni.showToast({
						title: "密码不能为空",
						icon: "none"
					});
					return;
				}
				
				if (this.password != this.confirmPassword) {
					uni.showToast({
						title: "两次密码不一致",
						icon: "none"
					});
					return;
				}
				
				if (!this.account) {
					uni.showToast({
						title: "账号不能为空",
						icon: "none"
					});
					return;
				}
				
				if (!this.phone) {
					uni.showToast({
						title: "手机号码不能为空",
						icon: "none"
					});
					return;
				}
				let params = {
					account: this.account,
					password: this.password,
					phone: this.phone,
					// invite_code: this.inviteCode
				}
				if(uni.getStorageSync('pid')) {
					params.mid = uni.getStorageSync('pid')
				}
				this.$api.post('/addons/yun_shop/api.php?route=member.register.mappindex',
					params).then(res => {
					if (res.result == 1) {
						params = {
							mobile: this.account,
							password: this.password,
						}
						this.$api.post('/addons/yun_shop/api.php?route=member.login.index',
							params).then(res => {
							if (res.result == 1) {
								//this.$store.commit(this.$tools.getCookieValueByKey("PHPSESSID"))
								// #ifdef APP-PLUS
								uni.switchTab({
									url: "/pages/prefile/prefile",
									fail (error) {
										console.log(error)
									}
								})
								// #endif
								// #ifdef H5
								uni.navigateTo({
									url: "/pages/prefile/prefile",
									fail (error) {
										console.log(error)
									}
								})
								// #endif
							}
						})
					}
				})
			},
			viewPwd () {
				this.isViewPwd = !this.isViewPwd;
				console.log(this.isViewPwd);
			},
			toLogin () {
				uni.navigateTo({
					url: "/pages/personal/login/login"
				})
			}
		}
	}
</script>

<style lang="scss">
	@import './register.scss';
</style>
